/*
 * $Id: SttpBase.h,v 1.5 2006-02-14 06:02:08 bacon Exp $
 */

#ifndef _XPP_NET_STTPBASE_CLASS_
#define _XPP_NET_STTPBASE_CLASS_

#include <xpp/net/ProtoBase.h>

namespace xpp
{
	namespace net
	{

		class SttpBase: public ProtoBase 
		{
		public:
			SttpBase (Transmittable* s = XP_NULL, Address* a = XP_NULL);
			virtual ~SttpBase ();
		
			void reset ();

			xp_time_t sendTimeout () const 
			{
				return send_timeout;
			}
			void enableSendTimeout (xp_time_t sec) 
			{
				send_timeout = sec;
			}
			void disableSendTimeout ()
			{
				send_timeout = -1;
			}
			xp_time_t receiveTimeout () const 
			{
				return receive_timeout;
			}
			void enableReceiveTimeout (xp_time_t sec) 
			{
				receive_timeout = sec;
			}
			void disableReceiveTimeout ()
			{
				receive_timeout = -1;
			}
		
			bool isReceiveCancelRequested () const 
			{
				return receive_cancel_requested;
			}
			void setReceiveCancelRequested (bool r) 
			{
				receive_cancel_requested = r;
			}
	
			virtual bool canCancelReceive ()
			{
				return false;
			}
		
			enum 
			{
				ERR_CANCEL = ProtoBase::__NERRCODES__,
				ERR_TIMEDOUT,
				ERR_UTF8_CONV,
				__NERRCODES__
			};
		
			const xp_char_t* errorStr () const;

		protected:			
			enum 
			{
				MAX_INBUF_LEN        = 1024,
				MAX_OUTBUF_LEN       = 1024
			};
		
			xp_time_t receive_timeout;
			xp_time_t send_timeout;
			bool receive_cancel_requested;
		
			xp_mchar_t inbuf [MAX_INBUF_LEN];
			xp_mchar_t outbuf[MAX_OUTBUF_LEN];
			xp_size_t  inbuf_len;
			xp_size_t  outbuf_len;
			xp_size_t  sttp_curp;
			xp_cint_t  sttp_curc;
		
			int  get_char (xp_cint_t* ch = XP_NULL);

			int  put_char (xp_cint_t ch);
			int  put_mchar (xp_mchar_t ch);

			int  flush_outbuf ();
		};
		
	}
}

#endif
		

